﻿using BO;
using BO.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebUI3.Models;
namespace WebUI3.Controllers
{
   
    public class LogonController : Controller
    {
        
        //
        // GET: /Logon/

        public ActionResult Index()
        {
            return View("Logon");
        }
        [HttpPost]
        public JsonResult Login(SysUserModel auser)
        {

            string pUserName = auser.UserName;
            string pPassword = auser.UserPwd;
            BOPrincipal.Logout();
            if (BOPrincipal.Login(pUserName, pPassword))
            {
                SysUser _User = null;
                if (Csla.ApplicationContext.User.Identity.Name == "SUPERUSER")
                {
                    _User = new SysUser();
                    _User.UserName = Csla.ApplicationContext.User.Identity.Name;
                    _User.UserPwd = Csla.ApplicationContext.User.Identity.Name;
                }
                else
                    _User = SysUser.Get(Csla.ApplicationContext.User.Identity.Name);

                Session["CurrentUser"] = _User;

                return Json("Success");
            }
            else
            {
                return Json("用户名或密码错误.");
            }

        }
        protected override void OnException(ExceptionContext filterContext)
        {
          
            filterContext.HttpContext.Response.Redirect("Error");
        
        }
    }
}
